package com.nd.android.u.ui.widge;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.common.utils.StarAppUtils;
import com.nd.android.u.ui.ChatEntry;
import com.nd.android.u.ui.R;
import com.product.android.business.ApplicationVariable;
import com.product.android.utils.SharedPreferenceHelper;

/**
 * ClassName:ChatAddFriendView
 * Function: 聊天界面添加陌生人为好友的控件
 * Reason:	 
 * @author   cb		
 * @version  Ver 1.0.0
 * @Date	 2014	2014-4-9		下午3:21:48
 *
 * @see 	 
 */
public class ChatAddFriendView extends LinearLayout {
	private long mUid;		//当前聊天对象的UID
	private Context mContext;
	private String mName;	//对方的姓名
	public ChatAddFriendView(Context context) {
		super(context);
		initView(context);
	}

	public ChatAddFriendView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	public ChatAddFriendView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView(context);
	}
	
	private void initView(Context context){
		mContext=context;
		LayoutInflater.from(context).inflate(R.layout.chat_add_friend_view, this);
		TextView tvAdd = (TextView)findViewById(R.id.tvAdd);
		TextView tvCancel = (TextView)findViewById(R.id.tvCancel);
		
		tvAdd.setOnClickListener(mOnClickListener);
		tvCancel.setOnClickListener(mOnClickListener);
		
		StarAppUtils.setViewTypeFace((TextView)findViewById(R.id.tvAddFriend), false);
		StarAppUtils.setViewTypeFace(tvAdd, false);
		StarAppUtils.setViewTypeFace(tvCancel, false);
	}
	
	public void setUid(long uid,String name){
		mUid=uid;
		mName=name;
	}
	
	private OnClickListener mOnClickListener=new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			int id=arg0.getId();
			if (id==R.id.tvAdd){
				//添加
				ChatEntry.INSTANCE.chatCallOtherModel_UI.addFriend((Activity) mContext,mUid,mName);
			}else if (id==R.id.tvCancel){
				//取消
				setVisibility(View.GONE);
			}else{
				//do nothing
			}
		}
	};
	
	/**
	 * @函数名称     :unRemind
	 * @brief 设置不再提醒
	 * @see
	 * @since    Ver 1.1
	 * @作者          :  Administrator
	 * @创建时间      :  2014-6-4下午3:23:26      
	*/
	public void unRemind(){
		SharedPreferenceHelper helper=SharedPreferenceHelper.getInstance();
		long self=ApplicationVariable.INSTANCE.getOapUid();
		String key=SharedPreferenceHelper.CONFIG_REMIND_FRIEND+self;
		String existValue=helper.loadKey(key);
		//先取出旧值
		if (TextUtils.isEmpty(existValue)){
			//没有旧值
			existValue=","+mUid+",";
		}else{
			//已有旧值，直接添加末尾
			existValue+=mUid+",";
		}
		helper.saveKey(key, existValue);
	}
	
	/**
	 * @函数名称     :isNeedShow
	 * @brief 是否需要显示添加好友的提示
	 * @see
	 * @since    Ver 1.1
	 * @return
	 * @作者          :  Administrator
	 * @创建时间      :  2014-5-12下午2:21:36      
	*/
	public boolean isNeedShow(){
		SharedPreferenceHelper helper=SharedPreferenceHelper.getInstance();
		long self=ApplicationVariable.INSTANCE.getOapUid();
		String key=SharedPreferenceHelper.CONFIG_REMIND_FRIEND+self;
		String nowValue=","+mUid+",";
		String existValue=helper.loadKey(key);
		if (existValue.indexOf(nowValue)>-1){
			return false;
		}
		return true;
	}
}
